package com.nt.train.entity;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
/**
 * 生命周期
 * https://blog.csdn.net/Strange_boy/article/details/123652576
 * https://blog.csdn.net/m0_57237237/article/details/122402815
 * @author hlf
 * @version 1.0
 * @date 2022/8/15 18:23
 */
public class Book implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {

    private String bookName;

    public String getBookName() {
        return bookName;
    }

    public Book() {
        System.out.println("1、构造方法执行了。。。。 ");
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
        System.out.println("2、设置属性执行了，书名是： " + getBookName());
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3、setBeanName 方法执行了。。。");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4、setBeanFactory 方法执行了。。。");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("5、setApplicationContext 方法执行了。。。");
    }

    //MyBeanPostProcessor.postProcessBeforeInitialization

    @PostConstruct
    public void springPostConstruct() {
        System.out.println("6、@PostConstruct 执行了。。。");
    }

    @Override
    public void afterPropertiesSet() {
        System.out.println("7、afterPropertiesSet 执行了。。。");
    }

    public void myPostConstruct() {
        System.out.println("8、自定义方法 myPostConstruct 执行了。。。");
    }

    //MyBeanPostProcessor.postProcessAfterInitialization
    //Book name = thing king in java

    @PreDestroy
    public void springPreDestroy() {
        System.out.println("9、@PreDestroy 方法执行了。。。");
    }

    @Override
    public void destroy() {
        System.out.println("10、destroy 方法执行了。。。");
    }

    public void myPreDestroy() {
        System.out.println("11、自定义方法 myPreDestroy 执行了。。。 ");
    }

    public String  testBookInfo(String bookName){
        return "使用book名称："+bookName ;
    }
}
